package com.hckjsec.official.controller;

import java.util.List;

import com.hckjsec.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hckjsec.common.annotation.Log;
import com.hckjsec.common.core.controller.BaseController;
import com.hckjsec.common.core.domain.AjaxResult;
import com.hckjsec.common.enums.BusinessType;
import com.hckjsec.official.domain.OfficialHonor;
import com.hckjsec.official.service.IOfficialHonorService;
import com.hckjsec.common.utils.poi.ExcelUtil;
import com.hckjsec.common.core.page.TableDataInfo;

/**
 * 公司网站图片Controller
 * 
 * @author cyt
 * @date 2021-12-02
 */
@RestController
@RequestMapping("/official/honor")
public class OfficialHonorController extends BaseController
{
    @Autowired
    private IOfficialHonorService officialHonorService;

    /**
     * 查询公司网站图片列表
     */
    @GetMapping("/list")
    public TableDataInfo list(OfficialHonor officialHonor)
    {
        startPage();
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            officialHonor.setDeptId(SecurityUtils.getDeptId());
        }
        List<OfficialHonor> list = officialHonorService.selectOfficialHonorList(officialHonor);
        return getDataTable(list);
    }

    /**
     * 导出公司网站图片列表
     */
    @Log(title = "公司网站图片", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OfficialHonor officialHonor)
    {
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            officialHonor.setDeptId(SecurityUtils.getDeptId());
        }
        List<OfficialHonor> list = officialHonorService.selectOfficialHonorList(officialHonor);
        ExcelUtil<OfficialHonor> util = new ExcelUtil<OfficialHonor>(OfficialHonor.class);
        return util.exportExcel(list, "honor");
    }

    /**
     * 获取公司网站图片详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(officialHonorService.selectOfficialHonorById(id));
    }

    /**
     * 新增公司网站图片
     */
    @Log(title = "公司网站图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OfficialHonor officialHonor)
    {
        officialHonor.setDeptId(SecurityUtils.getDeptId());
        officialHonor.setCreateBy(SecurityUtils.getUsername());
        return toAjax(officialHonorService.insertOfficialHonor(officialHonor));
    }

    /**
     * 修改公司网站图片
     */
    @Log(title = "公司网站图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OfficialHonor officialHonor)
    {
        officialHonor.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(officialHonorService.updateOfficialHonor(officialHonor));
    }

    /**
     * 删除公司网站图片
     */
    @Log(title = "公司网站图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(officialHonorService.deleteOfficialHonorByIds(ids));
    }
}
